#include "Cell.h"
#include "PartitionElement.h"
#include "Sudoku.h"

Cell::Cell():value(0)
{}
Cell::Cell( short newValue ):value( newValue )
{}

Cell::~Cell()
{}

short Cell::getValue()
{
    return value ;
}

bool Cell::setValue( short newValue )
{
    if( value != newValue )
    {
        PartitionElement* part = new PartitionElement( this, newValue ) ;
        part->setOldValue( value ) ;
        Sudoku::addPartitionElement( part ) ;
        value = newValue ;

        return true ;
    }
    return false ;
}

bool Cell::delAssum( short digit )
{
    if( true == assum.delAssum( digit ) )
    {
        Sudoku::addPartitionElement( new PartitionElement( this, digit, false ) ) ;
        return true ;
    }
    return false ;
}

bool Cell::addAssum( short digit )
{
    return assum.addAssum( digit ) ;
}

std::ostream& operator<<( std::ostream& out , Cell cell )
{
    out << cell.getValue() ;
    if ( 0 == cell.getValue() )
        out << " {" << cell.assum << '}' ;

    return out ;
}

Assumption& Cell::getAssumption()
{
    return assum ;
}

short Cell::count()
{
    return assum.count() ;
}

short Cell::getExclusive()
{
    return assum.getExclusive() ;
}


bool Cell::assumptionsIs()
{
    for( int index=1 ; index<10 ; ++index )
    {
        if( Can == assum.getAssum( index ) )
            return true ;
    }
    return false;
}
